﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PerfumeShopManagement.BLL;
using PerfumeShopManagement.Model;

namespace PerfumeShopManagement.View
{
    public partial class frmStatistics : Form
    {
        BllRepositoryHistory bllRepositoryHistory;

        public frmStatistics()
        {
            bllRepositoryHistory = new BllRepositoryHistory(); 
            InitializeComponent();
        }

        private void btnBegin_Click(object sender, EventArgs e)
        {
            int productId = 0;
            Product prod = new Product();
            prod.ProductName = cbbProduct.Text;
            List<Product> list = new BllProduct().Search(prod);
            if (list.Count > 0)
                productId = list[0].ProductId;

            lblQuantity.Text = bllRepositoryHistory.GetInventoryOfDay(
                dtpDay.Value, productId).ToString();
        }

        private void cbbProduct_TextChanged(object sender, EventArgs e)
        {
            ComboBox cbb = (ComboBox) sender;
            lblProduct.Text = cbb.Text;
            lblQuantity.Text = "?";
        }

        private void dtpDay_ValueChanged(object sender, EventArgs e)
        {
            lblQuantity.Text = "?";
        }

        private void frmStatistics_Load(object sender, EventArgs e)
        {
            dtpDay.Value = DateTime.Now;
            List<Product> products = new BllProduct().GetAll();
            foreach (Product product in products)
            {
                cbbProduct.Items.Add(product.ProductName);
            }
        }
    }
}
